package com.sorhis.controller;

import com.sorhis.dto.SysRoleDTO;
import com.sorhis.dto.SysTenantDTO;
import com.sorhis.service.ISysRoleService;
import com.sorhis.service.ISysTenantService;
import com.sorhis.vo.ResultVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xihao.ding
 * @since 2025-02-11
 */
@RestController
@RequestMapping("/sysTenant/v1")
@RequiredArgsConstructor
public class SysTenantController {

    private final ISysTenantService sysTenantService;
    private final ISysRoleService sysRoleService;

    @GetMapping(value = "/list")
    public ResultVO search(SysTenantDTO sysTenantDTO) {
        return ResultVO.ok(sysTenantService.findPageList(sysTenantDTO));
    }

    @PostMapping(value = "/save")
    public ResultVO saveOrUpateUser(@RequestBody SysTenantDTO sysTenantDTO) {
        return ResultVO.ok(sysTenantService.saveOrUpateDomain(sysTenantDTO));
    }

    @PostMapping(value = "/del/{id}")
    public ResultVO del(@PathVariable String id) {
        return ResultVO.ok(sysTenantService.del(id));
    }

    @GetMapping(value = "/tree")
    public ResultVO tree() {
        return ResultVO.ok(sysTenantService.tree());
    }

    /**
     * 租户角色列表
     * @param sysRoleDTO
     * @return
     */
    @GetMapping(value = "/role/list")
    public ResultVO roleTenantPage(SysRoleDTO sysRoleDTO) {
        return ResultVO.ok(sysTenantService.roleTenantPage(sysRoleDTO));
    }

    /**
     * 租户角色保存
     * @param sysRoleDTO
     * @return
     */
    @PostMapping(value = "/role/save")
    public ResultVO roleTenantSave(@RequestBody SysRoleDTO sysRoleDTO) {
        return ResultVO.ok(sysRoleService.saveOrUpateDomain(sysRoleDTO));
    }

    /**
     * 租户角色删除
     * @return
     */
    @PostMapping(value = "/role/del/{id}")
    public ResultVO roleTenantDel(@PathVariable String id) {
        return ResultVO.ok(sysRoleService.del(id));
    }


}
